home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / Cutscene / CutsceneDialogue.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  7.7 KB  |  288 lines

  1. package Cutscene
  2. {
  3.    import Common.ResourceManager;
  4.    import caurina.transitions.Tweener;
  5.    import flash.display.*;
  6.    import flash.media.Sound;
  7.    import flash.text.TextField;
  8.    
  9.    public class CutsceneDialogue
  10.    {
  11.       
  12.       public static var txtOwner:TextField;
  13.       
  14.       public static var txtOwnerbg_mc:MovieClip;
  15.       
  16.       public static var txtDialogue:TextField;
  17.       
  18.       public static var dialogueBox:MovieClip = null;
  19.       
  20.       public static var txtSkipButton_mc:SimpleButton;
  21.       
  22.       public static var txtSkip:TextField;
  23.        
  24.       
  25.       private var delay:int = 2;
  26.       
  27.       private var animplay:String = "";
  28.       
  29.       private var movey:int = -100;
  30.       
  31.       private var hidebox:String = "";
  32.       
  33.       private var movex:int = -100;
  34.       
  35.       private var dialogue:String = "";
  36.       
  37.       private var initialalpha:int = 20;
  38.       
  39.       private var decisions:Array;
  40.       
  41.       private var soundFX:String = "";
  42.       
  43.       private var namexpos:int = -100;
  44.       
  45.       private var finalalpha:int = -100;
  46.       
  47.       private var owner:String = "";
  48.       
  49.       private var puppet:String = "";
  50.       
  51.       public function CutsceneDialogue()
  52.       {
  53.          owner = "";
  54.          puppet = "";
  55.          dialogue = "";
  56.          soundFX = "";
  57.          movex = -100;
  58.          movey = -100;
  59.          namexpos = -100;
  60.          delay = 2;
  61.          initialalpha = 20;
  62.          finalalpha = -100;
  63.          animplay = "";
  64.          hidebox = "";
  65.          decisions = [];
  66.          super();
  67.       }
  68.       
  69.       public static function fromXML(param1:XML, param2:MovieClip) : CutsceneDialogue
  70.       {
  71.          var _loc3_:CutsceneDialogue = null;
  72.          var _loc4_:XML = null;
  73.          _loc3_ = new CutsceneDialogue();
  74.          _loc3_.dialogue = Localization.getString(param1.toString());
  75.          for each(_loc4_ in param1.attributes())
  76.          {
  77.             if(_loc4_.name() == "owner")
  78.             {
  79.                _loc3_.owner = _loc4_.toString();
  80.             }
  81.             else if(_loc4_.name() == "sound")
  82.             {
  83.                _loc3_.soundFX = _loc4_.toString();
  84.             }
  85.             else if(_loc4_.name() == "puppet")
  86.             {
  87.                _loc3_.puppet = _loc4_.toString();
  88.             }
  89.             else if(_loc4_.name() == "movex")
  90.             {
  91.                _loc3_.movex = _loc4_.toString();
  92.             }
  93.             else if(_loc4_.name() == "movey")
  94.             {
  95.                _loc3_.movey = _loc4_.toString();
  96.             }
  97.             else if(_loc4_.name() == "delay")
  98.             {
  99.                _loc3_.delay = _loc4_.toString();
  100.             }
  101.             else if(_loc4_.name() == "namexpos")
  102.             {
  103.                _loc3_.namexpos = _loc4_.toString();
  104.             }
  105.             else if(_loc4_.name() == "alpha")
  106.             {
  107.                _loc3_.initialalpha = _loc4_.toString();
  108.             }
  109.             else if(_loc4_.name() == "finalalpha")
  110.             {
  111.                _loc3_.finalalpha = _loc4_.toString();
  112.             }
  113.             else if(_loc4_.name() == "anim")
  114.             {
  115.                _loc3_.animplay = _loc4_.toString();
  116.             }
  117.             else if(_loc4_.name() == "hidebox")
  118.             {
  119.                _loc3_.hidebox = _loc4_.toString();
  120.             }
  121.             else
  122.             {
  123.                _loc3_.decisions.push(_loc4_.toString());
  124.             }
  125.          }
  126.          return _loc3_;
  127.       }
  128.       
  129.       public function updateTextElement(param1:int) : *
  130.       {
  131.          if(param1 - 1 < dialogue.length)
  132.          {
  133.             txtDialogue.text = dialogue.slice(0,param1);
  134.          }
  135.       }
  136.       
  137.       public function get LengthOfText() : *
  138.       {
  139.          return dialogue.length;
  140.       }
  141.       
  142.       public function get Owner() : String
  143.       {
  144.          return owner;
  145.       }
  146.       
  147.       public function hasDecision() : Boolean
  148.       {
  149.          return decisions.length > 0;
  150.       }
  151.       
  152.       public function initializeDialogue(param1:ResourceManager, param2:CutsceneState) : int
  153.       {
  154.          var _loc3_:MovieClip = null;
  155.          var _loc4_:Sound = null;
  156.          var _loc5_:* = undefined;
  157.          _loc3_ = param2.getPerson(owner);
  158.          if(hidebox != "")
  159.          {
  160.             if(dialogueBox != null)
  161.             {
  162.                Tweener.addTween(dialogueBox,{
  163.                   "alpha":0,
  164.                   "time":delay
  165.                });
  166.             }
  167.             Tweener.addTween(txtDialogue,{
  168.                "alpha":0,
  169.                "time":delay
  170.             });
  171.             Tweener.addTween(txtOwner,{
  172.                "alpha":0,
  173.                "time":delay
  174.             });
  175.             txtSkip.visible = false;
  176.             txtSkipButton_mc.visible = false;
  177.             return 2;
  178.          }
  179.          if(animplay != "")
  180.          {
  181.             _loc3_.gotoAndPlay(animplay);
  182.             return 2;
  183.          }
  184.          if(movex != -100)
  185.          {
  186.             _loc3_.alpha = initialalpha / 100;
  187.             Tweener.addTween(_loc3_,{
  188.                "alpha":1,
  189.                "time":delay
  190.             });
  191.             Tweener.addTween(_loc3_,{
  192.                "x":movex,
  193.                "time":delay
  194.             });
  195.             movex = -100;
  196.             return 2;
  197.          }
  198.          if(movey != -100)
  199.          {
  200.             _loc3_.alpha = initialalpha / 100;
  201.             Tweener.addTween(_loc3_,{
  202.                "alpha":1,
  203.                "time":delay
  204.             });
  205.             Tweener.addTween(_loc3_,{
  206.                "y":movey,
  207.                "time":delay
  208.             });
  209.             movey = -100;
  210.             return 2;
  211.          }
  212.          if(finalalpha != -100)
  213.          {
  214.             _loc3_.alpha = initialalpha / 100;
  215.             Tweener.addTween(_loc3_,{
  216.                "alpha":finalalpha / 100,
  217.                "time":delay
  218.             });
  219.             finalalpha = -100;
  220.             return 2;
  221.          }
  222.          txtOwner.text = owner;
  223.          if(namexpos == -100)
  224.          {
  225.             txtOwnerbg_mc.x = _loc3_.x;
  226.          }
  227.          else
  228.          {
  229.             txtOwnerbg_mc.x = namexpos;
  230.          }
  231.          if((_loc4_ = param1.getResource(soundFX,ResourceManager.C_SOUND) as Sound) != null)
  232.          {
  233.             _loc4_.play();
  234.          }
  235.          if(decisions.length > 0)
  236.          {
  237.             _loc5_ = 0;
  238.             while(_loc5_ < decisions.length)
  239.             {
  240.                param2.getDecision(decisions[_loc5_]).attachToParent();
  241.                _loc5_++;
  242.             }
  243.          }
  244.          return 1;
  245.       }
  246.       
  247.       public function addDecision(param1:String) : *
  248.       {
  249.          this.decisions.push(param1);
  250.       }
  251.       
  252.       public function talk(param1:CutsceneState, param2:int) : *
  253.       {
  254.          var _loc3_:MovieClip = null;
  255.          if(param2 - 1 >= dialogue.length)
  256.          {
  257.             return;
  258.          }
  259.          _loc3_ = param1.getPerson(puppet);
  260.          if(_loc3_ == null)
  261.          {
  262.             return;
  263.          }
  264.          if(_loc3_.mouth == null)
  265.          {
  266.             return;
  267.          }
  268.          if(_loc3_.mouth.currentLabel == "mouth" && isVowel(dialogue.charAt(param2)))
  269.          {
  270.             _loc3_.mouth.gotoAndPlay("mouthopen");
  271.          }
  272.          else if(_loc3_.mouth.currentLabel == "mouthopen" && !isVowel(dialogue.charAt(param2)))
  273.          {
  274.             _loc3_.mouth.gotoAndPlay("mouth");
  275.          }
  276.       }
  277.       
  278.       public function isVowel(param1:String) : Boolean
  279.       {
  280.          if(param1 == "a" || param1 == "A" || param1 == "e" || param1 == "E" || param1 == "i" || param1 == "I" || param1 == "o" || param1 == "O" || param1 == "u" || param1 == "U")
  281.          {
  282.             return true;
  283.          }
  284.          return false;
  285.       }
  286.    }
  287. }
  288.